package cn.edu.abc.wangzi.ui;
/*
 *  项目名：Wangzi
 *  包名：cn.edu.abc.wangzi.ui
 *  创建者：SKFsky
 *  创建时间：2017/8/26 20:05
 *  描述:   闪屏效果
 */

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import cn.edu.abc.wangzi.R;
import cn.edu.abc.wangzi.utils.ShareUtils;
import cn.edu.abc.wangzi.utils.StaticClass;
import cn.edu.abc.wangzi.utils.UtilTools;

public class SplashActivity extends AppCompatActivity{

    private TextView tv_splash;
    private Handler handler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case StaticClass.HANDLER_SPLASH:
                        if (isFirst()){
                                startActivity(new Intent(SplashActivity.this,GuideActivity.class));
                        }else{
                            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                        }
                        finish();
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        initView();
    }

    private void initView() {
        handler.sendEmptyMessageDelayed(StaticClass.HANDLER_SPLASH,3000);
        tv_splash = (TextView) findViewById(R.id.tv_splash);
        UtilTools.setFont(SplashActivity.this,tv_splash);
    }

//判断程序是否是第一次运行
    private boolean isFirst() {
        boolean isFirst = ShareUtils.getBoolean(SplashActivity.this,StaticClass.SHARE_IS_FIRST,true);
        if (isFirst){
            ShareUtils.putBoolean(this,StaticClass.SHARE_IS_FIRST,false);
            return true;
        }else{
            return false;
        }
    }
}
